/*
 * TransparentBitbltLayerMerger.h
 *
 *  Created on: 2010-9-20
 *      Author: wenjian
 */

#ifndef TRANSPARENTBITBLTLAYERMERGER_H_
#define TRANSPARENTBITBLTLAYERMERGER_H_
#include "../draw/LayerMerger.h"
#include "gdiplus_commons.h"

namespace Ed {
  class DrawPage;
  class Layer;

  /**
   * 指定透明色的Bitblt模式层合并, 可指定一种颜色作为透明色，会损失部份性能
   */
  class TransparentBitbltLayerMerger: public Ed::LayerMerger {
    public:
      TransparentBitbltLayerMerger(DrawPage* page, COLORREF transparentColor);
      virtual ~TransparentBitbltLayerMerger();

      /**
       * 将图层与目标设备合并
       */
      virtual bool merge();

    private:
      DrawPage* page;
      COLORREF transparentColor;

      struct BufferItem{
          HDC bufferDC;
          HDC maskDC;
          Gdiplus::Graphics* graphics;
      };

      typedef hash_map<long, BufferItem*> LayerBufferMap;
      LayerBufferMap layerBufferMap;

      /**
       * 返回BufferItem
       */
      BufferItem* getBufferItem(Layer* l);
  };

}

#endif /* TRANSPARENTBITBLTLAYERMERGER_H_ */
